package com.zhu.day.sunfa;

/**
 * 数组练习
 */
public class ArrayTest {
    //有序数据去重,输出新数组的长度
    public static void main(String[] args) {
        int nums[] = new int[]{1, 1, 2};
        int i = removeDuplicates(nums);
        System.out.println(i);


    }

    /**
     *
     * @param nums
     * @return
     */
    public static int removeDuplicates(int[] nums) {
        int left = 0;
        if (nums == null || nums.length == 0) {
            return left;
        }
        for (int right = 0; right < nums.length; right++) {
            if (nums[left] != nums[right]) {
                nums[++left] = nums[right];
                ++left;
            }
        }
        return left;
    }
}
